#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int paddingOOB(FILE *out_fp) {
	int loop = 64;
	unsigned char pad = 0xFF;
	for(int i=0; i<loop; i++)
		fwrite(&pad, 1, 1, out_fp);
	
	return 0;
}

int main(int argc, char**argv) {
  char *src_name = NULL;
  char *out_name = NULL;
  FILE * src_fp = NULL;
  FILE *out_fp = NULL;
  char buffer[2048];
  int lens=2048;
  size_t size = 0;
  size_t read_cnt = 0, write_cnt = 0;
  
  if(argc != 3) {
    printf("argc is err\n");
    return 0;
  }

  src_name = argv[1];
  out_name = argv[2];

  fprintf(stderr, "src_name: %s, out_name: %s\n", src_name, out_name);

  src_fp = fopen (src_name, "rb");
  if(src_fp == NULL) {
	  fprintf(stderr, "Unable to open the file: %s\n", src_name);
	  return 0;
  }
  
  out_fp = fopen (out_name, "wb+");
  if(out_fp == NULL) {
	  fprintf(stderr, "Unable to open the file: %s\n", out_name);
	  return 0;
  }

  //求得文件的大小
  fseek(src_fp, 0, SEEK_END);
  size = ftell(src_fp);
  rewind(src_fp);

  fprintf(stderr, "get file %s size: %ld\n", src_name, size);
  while(!feof(src_fp)) {
	read_cnt = fread(buffer, lens, 1, src_fp);
	write_cnt = fwrite(buffer, lens, 1, out_fp);
	if(read_cnt == 1) {
		paddingOOB(out_fp);
	} else {
		printf("read_cnt=%d\n", read_cnt);
	}
  }

  fclose(src_fp);
  fclose(out_fp);
  return 0;

}
